<?php
	// function to mark bill as paid
	if (isset($_GET['paid'])) {
		setBillPaid($_POST['billid'], $_SESSION['username']);
	}
	
	$bills = getBills($_SESSION['username']);
	
	//continue on to display bills again
	echo '<div id="bills">
			<h3>Bills</h3>
			';
	
	if (!$bills || (mysql_numrows($bills) < 1)) {
		echo '<p>There are no bills to display.</p>';
	}
	else {
		while ($row = mysql_fetch_array($bills)) {
			if ($row[5] == NULL || $row[5] == "") {
				echo '<fieldset>';
				echo '<p>Bill: ' . $row[1] . '</p>
						<p>Bill Total: $' . getBillTotal($row[0]) . '</p>
						<p>Your share: $' .$row[2] . '</p>
						<p>Date Due: ' .$row[3] . '</p>
						';
				if ($row[4] == NULL || $row[4] == "") {
					// form data to give "paid" button
					echo '
						<form name="payBill" id="payBill" method="post" action="?viewbills&paid">
						<input type="hidden" name="billid" id="billid" value="' . $row[0] . '" />
						<input type="submit" value="Paid" />
						</form>
						';
				}
				else {
					echo '<p>Paid on: ' . $row[4] . '</p>
						<p>Awaiting confirmation from the bill payer.</p>
						';
				}
				echo '</fieldset>
				';
			}
		}
	}
	echo '</div>';
	
	
	// function to mark chore as completed
	if (isset($_GET['completed'])) {
		setChoreCompleted($_POST['billid'], $_SESSION['username']);
	}
	
	$chores = getChores($_SESSION['username']);
	
	//continue on to display bills again
	
	echo '<div id="chores">
			<h3>Chores</h3>
			';
	
	if (!$chores || (mysql_numrows($chores) < 1)) {
		echo '<p>There are no chores to display.</p>';
	}
	else {
		while ($row = mysql_fetch_array($chores)) {
			if ($row[3] == NULL || $row[3] == "") {
				echo '<fieldset>';
				echo '<p>Chore: ' . $row[1] . '</p>
						<p>Date Due: ' .$row[2] . '</p>
						';
				
				// form data to give "completed" button
				echo '
					<form name="completeChore" id="completeChore" method="post" action="?viewbills&completed">
					<input type="hidden" name="billid" id="billid" value="' . $row[0] . '" />
					<input type="submit" value="Click to Complete Chore" />
					</form>
					';
				
				echo '</fieldset>
				';
			}
		}
	}
	echo '</div>';
?>